package com.carleasoft.mps.cms.business.repairs.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carleasoft.mps.cms.business.repairs.bean.entity.RepairsGroup;
import com.carleasoft.mps.cms.business.repairs.bean.entity.EquipmentMessage;
import com.carleasoft.mps.cms.business.repairs.bean.po.*;
import com.carleasoft.mps.cms.business.repairs.bean.vo.EquipmentStatisticsVo;
import com.carleasoft.mps.cms.business.repairs.bean.vo.QueryIsDealPersonVo;
import com.carleasoft.mps.cms.business.repairs.bean.vo.EquipmentMessageDetailVo;
import com.carleasoft.mps.cms.business.repairs.service.EquipmentMessageService;
import com.carleasoft.mps.core.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 器材申请 前端控制器
 * </p>
 *
 * @author fan
 * @since 2023-06-02
 */
@RestController
@RequestMapping("/equipmentMessage")
public class EquipmentMessageController {
    @Autowired
    private EquipmentMessageService equipmentMessageService;

    /**
     * 器材申请添加接口
     */
    @PostMapping("/equipmentAdd")
    public R equipmentAdd(@RequestBody EquipmentMessageAddOrEditPo equipmentMessageAddOrEditPo) {
        return R.ok(equipmentMessageService.equipmentAdd(equipmentMessageAddOrEditPo));
    }

    /**
     * 导入器材申请
     * @param file
     * @return
     */
    @PostMapping("/equipmentExcel")
    public R equipmentExcel(@RequestPart("file") MultipartFile file) {
        boolean isOk = equipmentMessageService.equipmentExcel(file);
        return R.ok(isOk);
    }

    /**
     * 器材申请分页接口
     */
    @PostMapping("/equipmentPage")
    public R<Page<EquipmentMessage>> equipmentPage(@RequestBody EquipmentMessagePagePo equipmentMessagePagePo) {
        return R.ok(equipmentMessageService.equipmentPage(equipmentMessagePagePo));
    }

    /**
     * 器材申请数据分页接口
     */
    @PostMapping("/myEquipmentPage")
    public R<Page<EquipmentMessage>> myEquipmentPage(@RequestBody EquipmentMessagePagePo equipmentMessagePagePo) {
        return R.ok(equipmentMessageService.myEquipmentPage(equipmentMessagePagePo));
    }

    /**
     * 器材申请详情接口
     */
    @PostMapping("/equipmentDetail")
    public R<EquipmentMessageDetailVo> equipmentDetail(@RequestBody EquipmentMessage equipmentMessage) {
        return R.ok(equipmentMessageService.equipmentDetail(equipmentMessage));
    }

    /**
     * 器材申请处理接口
     */
    @PostMapping("/equipmentDeal")
    public R<Boolean> equipmentDeal(@RequestBody EquipmentMessageDealPo equipmentMessageDealPo) {
        return R.ok(equipmentMessageService.equipmentDeal(equipmentMessageDealPo));
    }

    /**
     * 器材申请维修反馈接口
     */
    @PostMapping("/equipmentFeedback")
    public R<Boolean> equipmentFeedback(@RequestBody EquipmentFeedbackPo equipmentFeedbackPo) {
        return R.ok(equipmentMessageService.equipmentFeedback(equipmentFeedbackPo));
    }

    /**
     * 器材申请派单人员查询
     */
    @PostMapping("/sendPersonListEqu")
    public R<List<RepairsGroup>> sendPersonList(@RequestBody SendPersonListPo sendPersonListPo) {
        return R.ok(equipmentMessageService.sendPersonList(sendPersonListPo));
    }

    /**
     * 重新派工接口
     */
    @PostMapping("/anewEqu")
    public R anew(@RequestBody AnewPo anewPo) {
        return R.ok(equipmentMessageService.anew(anewPo));
    }

    /**
     * 查询当前登录人是否是综合处理人
     */
    @PostMapping("/queryIsDealPersonEqu")
    public R<QueryIsDealPersonVo> queryIsDealPerson() {
        return R.ok(equipmentMessageService.queryIsDealPerson());
    }

    /**
     * 导出器材申请记录
     */
    @PostMapping("/exportEqu")
    public R export(@RequestBody EquipmentMessagePagePo equipmentMessagePagePo, HttpServletResponse response) {
        return R.ok(equipmentMessageService.export(equipmentMessagePagePo, response));
    }

    /**
     * 办公统计-器材申请
     */
    @PostMapping("/online/statisticsEqu")
    public R<EquipmentStatisticsVo> statistics() {
        return R.ok(equipmentMessageService.statistics());
    }

    /**
     * 办公统计-器材申请-年度报修数量统计
     */
    @PostMapping("/online/statistics/theYearEqu")
    public R statisticsTheYear() {
        return R.ok(equipmentMessageService.statisticsTheYear());
    }

    /**
     * 办公统计-器材申请-维修率统计
     */
    @PostMapping("/online/statistics/MaintainRateEqu")
    public R MaintainRate() {
        return R.ok(equipmentMessageService.MaintainRate());
    }
}

